<template>
	<view>
		<view class="cu-custom my-bar" :style="[{height:CustomBar + 'px'}]" v-if="type">
			<view v-if="type=='name'" class="cu-bar bg-gradual-green fixed" :style="style" :class="[bgImage!=''?'none-bg text-white bg-img':'',bgColor]">
				<!--<view class="cu-avatar round" :style="'background-image:url('+this.logo+');'"></view>-->
				<image :src="logo" class="cu-avatar round logo" v-if="showLogo" />
				<view class="content" :style="[{top:StatusBar + 'px'}]">
					{{contentText||appName}}
				</view>
				<view class="action">
					<!-- #ifdef APP-PLUS -->
					<scan></scan>
					<!-- #endif -->
				</view>  
			</view>
			<view v-else-if="type=='search'" class="cu-bar bg-gradual-green search fixed" :style="style" :class="[bgImage!=''?'none-bg text-white bg-img':'',bgColor]">
				<!--<view class="cu-avatar round" :style="'background-image:url('+this.logo+');'"></view>-->
				<image :src="logo" class="cu-avatar round" />
				<view class="search-form round bg-green">
					<text class="cuIcon-search"></text>
					<input :adjust-position="false" placeholder="搜索……" confirm-type="search" disabled/>
					<!-- <input adjust-position="false" placeholder="搜索故事、案例、笑话" confirm-type="search" @click="softKeyUp" @focus="softKeyUp"
					  @blur="softKeyDown"></input> -->
				</view>
				<view class="action">
					<button class="cu-btn bg-gradual-green shadow-blur round">搜索</button>
				</view>
			</view>
			<view v-else-if="type=='back'" class="cu-bar bg-gradual-green fixed" :style="style" :class="[bgImage!=''?'none-bg text-white bg-img':'',bgColor]">
				<view class="action flex justify-end" @tap="BackPage">
					<text class="cuIcon-back margin-right-xl"></text>	
					<!--#ifdef MP-->
					<slot name="backText"></slot>
					<!--#endif-->					
					<!--#ifdef MP-->
					<slot name="content">会员中心</slot>
					<!--#endif-->							
				</view>
				<!--#ifndef MP-->
				<view class="content" :style="[{top:StatusBar + 'px'}]">
					<slot name="content">会员中心</slot>
				</view>
				<slot name="right"></slot>
				<!--#endif-->
			</view>
		</view>
	</view>
</template>

<script>
	import scan from '@/components/my-scan/scan.vue';
	import http from '@/common/http'
	import {
		mapState,
		mapMutations
		
	} from 'vuex';
	export default {
		components: {
			scan		
		},
		mounted: function() {
			//this.appName = getApp().globalData.appName;
			/* uni.getSystemInfo({
				success: (res) => {
					this.windowHeight = res.windowHeight;
				}
			});
			uni.onWindowResize((res) => {				
				if (res.size.windowHeight < this.windowHeight) {
					this.isSoftKeyUp = true			
				} else { 
					this.isSoftKeyUp = false  
				}
				this.$emit("softKeyUp", this.isSoftKeyUp);
			}) */
		},
		data() {
			const globalData = getApp().globalData
			return {
				StatusBar: globalData.StatusBar||uni.getSystemInfoSync().statusBarHeight + 'px',
				CustomBar: globalData.CustomBar||"44upx",		
				/* isSoftKeyUp: false, //软键盘是否弹起
				windowHeight: '' */
			};
		},
		name: 'my-bar',
		computed: {
			...mapState("base", ['logo','appName']),
			style() {
				const globalData = getApp().globalData
				var StatusBar = globalData.StatusBar;
				var CustomBar = globalData.CustomBar;
				var bgImage = this.bgImage;
				var style = `height:${CustomBar}px;padding-top:${StatusBar}px;`;
				if (this.bgImage) {
					style = `${style}background-image:url(${bgImage});`;
				}
				return style
			}
		},
		props: {
			contentText:{
				type: String,
				default: ''
			},
			bgColor: {
				type: String,
				default: ''
			},
			type: {
				type: String,
				default: 'back' //name应用名字  search搜索框  back返回
			},
			bgImage: {
				type: String,
				default: ''
			},
			showLogo: {
				type: Boolean,
				default: true
			},
		},
		methods: {
			BackPage() {
				this.$util.back();
			}			
			/* ,
						softKeyDown() {
							this.isSoftKeyUp = false; 
							uni.showModal({
								content:"11"+(this.isSoftKeyUp).toString()  
							})
							this.$emit("softKeyUp", this.isSoftKeyUp);
						},
						softKeyUp() {
							this.isSoftKeyUp = true;
							uni.showModal({
								content:"22"+(this.isSoftKeyUp).toString()  
							})
							this.$emit("softKeyUp", this.isSoftKeyUp);
						} */
		}
	}
</script>

<style>
	.cu-bar.search .search-form {
		margin: 0 10px;
		margin-right: 5px;
	}

	.cu-bar.search .search-form+.action {
		margin-right: 10px;
	}
</style>
